const webpack = require("webpack")
const entry = require('./webpack.entry.js')

// 分离css  > extract-text-webpack-plugin@next
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

// 清除目录
const CleanWebpackPlugin = require("clean-webpack-plugin")
const HtmlWebpackPlugin = require('html-webpack-plugin')
// 压缩
const optimizeCss = require('optimize-css-assets-webpack-plugin')

let html = []

Object.keys(entry).forEach(k => {
    let h = new HtmlWebpackPlugin({
        title: k,
        filename: `./pages/${k}.html`,
        template: `./src/pages/${k}.html`,
        inject: true,
        chunks: [k]
    })
    html.push(h)
})

module.exports = [
    new CleanWebpackPlugin(['superStyle']),
    // new ExtractTextPlugin("./style/[name].css"),
    new optimizeCss({
        assetNameRegExp: /\.style\.css$/g,
        cssProcessor: require('cssnano'),
        cssProcessorOptions: { discardComments: { removeAll: true } },
        canPrint: true
    }),
    new MiniCssExtractPlugin({
        filename: "css/[name].[contenthash].css",
        chunkFilename: "css/[name].[contenthash].css"
    }),
    new HtmlWebpackPlugin({
        title: "",
        filename: `./index.html`,
        template: `./index.html`,
        inject: true,
        chunks: ['main']
    })
].concat(html)